package edu.ucsd.cs110.mycity.model.data;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;

import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;

import edu.ucsd.cs110.mycity.ChatActivity;
import edu.ucsd.cs110.mycity.MyOverlay;

public class Buddy extends MyOverlay {
	private Context mContext;
	private String username;
	private Activity act;
	private boolean isNear;
	private boolean prevNear;

	public Buddy(Drawable defaultMarker, MapView mapView) {
		super(defaultMarker, mapView);
		mContext = mapView.getContext();
	}
	
	@SuppressLint("NewApi")
	@Override
	protected boolean onBalloonTap(int index, OverlayItem item) {
		Intent intent = new Intent(mContext, ChatActivity.class);
		intent.putExtra("to", username);
		act.startActivity(intent);
		return true;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getUsername() {
		return username;
	}

	public void setAct(Activity act) {
		this.act = act;
	}

	public Activity getAct() {
		return act;
	}

	public void dist(double longitude, double latitude) {
		if(Math.sqrt(longitude*longitude + latitude*latitude) < 10.0)
			this.isNear = true;
		else
			this.isNear = false;;
	}

	// Whether buddy is within 10 miles
	public boolean isNear() {
		return isNear;
	}

	public void setPrevNear(boolean prevNear) {
		this.prevNear = prevNear;
	}

	public boolean isPrevNear() {
		return prevNear;
	}
}
